package com.jrzh.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
@Table(name = "user")
public class User implements Serializable{
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	private Long id;
	
	@Column(nullable = false)
	private String name;

	@Column(nullable = false)
	private Integer age;
	
	private String password;
	
	@ManyToOne
	@JoinColumn(name = "did")
	@JsonBackReference
	private Department department;
	
	@ManyToMany(cascade = {},fetch = FetchType.EAGER)
	@JoinTable(name = "user_role",
					joinColumns = {@JoinColumn(name = "user_id")},
					inverseJoinColumns = {@JoinColumn(name = "roles_id")})
	private List<Role> roles;
	
	
	public User() {
	}
	
	public User(String name,Integer age) {
		this.name = name;
		this.age = age;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public Integer getAge() {
		return age;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	
	public String getPassword() {
		return password;
	}

	public Department getDepartment() {
		return department;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	@Override
	public String toString() {
		return "id【"+this.id+"】"+"name【"+this.name+"】"+"age【"+this.age+"】";
	}
	
	
}
